package com.fafu.rbac.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.fafu.common.web.bean.PageBean;
import com.fafu.common.web.bean.Result;
import com.fafu.common.web.bean.ResultUtil;
import com.fafu.common.web.controller.BaseController;
import com.fafu.common.web.mybatis.QueryWrapperUtil;
import com.fafu.rbac.conterter.RoleConverter;
import com.fafu.rbac.domain.entity.Role;
import com.fafu.rbac.domain.query.RoleQuery;
import com.fafu.rbac.domain.vo.RoleVO;
import com.fafu.rbac.service.RoleService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
* (tb_role)表控制层
*
* @author hc
*/
@RestController
@RequestMapping("/role")
public class RoleController extends BaseController<Role> {

    @Resource
    private RoleService roleService;

    public RoleController(IService<Role> service) {
        super(service);
    }

    @PostMapping("/list")
    public Result list(@RequestBody RoleQuery roleQuery){
        IPage<Role> page = new Page<>(roleQuery.getPageNum(),roleQuery.getPageSize());

        QueryWrapper<Role> queryWrapper = QueryWrapperUtil.build(roleQuery);

        roleService.page(page,queryWrapper);

        PageBean<Role> pageBean = PageBean.init(page);

        PageBean<RoleVO> roleVOPageBean = new RoleConverter().entityPageBean2VOPageBean(pageBean);

        return ResultUtil.success().addData("pageBean",roleVOPageBean);
    }



}
